package com.rc.saas.tenant.common.vo;

import com.rc.saas.tenant.common.base.HttpConstant;
import com.rc.saas.tenant.common.constant.CommonConstant;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 出参容器
 * Created by sven on 2018-02-09 15:43
 */
public class TResponse {
    private int status; //200:成功；其它:失败
    private String message;
    private Object data;

    public TResponse() {
    }

    public TResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public TResponse(int status, String message, Object data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public void put(Object value) {
        this.data = value;
    }

    public static TResponse SUCCESS() {
        return new TResponse(HttpConstant.STATUS_SUCCESS, CommonConstant.MSG_SUCCESS);
    }

    public static TResponse SUCCESS(String message) {
        return new TResponse(HttpConstant.STATUS_SUCCESS, message);
    }

    public static TResponse SUCCESS_DATA(Object object) {
        TResponse tResponse = new TResponse(HttpConstant.STATUS_SUCCESS, CommonConstant.MSG_SUCCESS);
        tResponse.setData(object);
        return tResponse;
    }

    public static TResponse SUCCESS_DATA_MESSAGE(Object object, String message) {
        TResponse tResponse = new TResponse(HttpConstant.STATUS_SUCCESS, message);
        tResponse.setData(object);
        return tResponse;
    }

    public static TResponse SUCCESS_CODE_MESSAGE(Integer code, String message) {
        TResponse tResponse = new TResponse(code, message);
        return tResponse;
    }

    public static TResponse FAIL() {
        return new TResponse(HttpConstant.STATUS_FAIL, CommonConstant.MSG_FAIL);
    }

    public static TResponse FAIL(String message) {
        return new TResponse(HttpConstant.STATUS_FAIL, message);
    }

    public static TResponse SC_OK() {
        return new TResponse(HttpServletResponse.SC_OK, "SC_OK");
    }

    public static TResponse SC_NOT_FOUND() {
        return new TResponse(HttpServletResponse.SC_NOT_FOUND, "SC_NOT_FOUND");
    }

    public static TResponse SC_BAD_REQUEST() {
        return new TResponse(HttpServletResponse.SC_BAD_REQUEST, "SC_BAD_REQUEST");
    }

    public static TResponse SC_FORBIDDEN() {
        return new TResponse(HttpServletResponse.SC_FORBIDDEN, "未授权访问");
    }

    public static TResponse SC_UNAUTHORIZED() {
        return new TResponse(HttpServletResponse.SC_UNAUTHORIZED, "SC_UNAUTHORIZED");
    }

    public static TResponse SC_INTERNAL_SERVER_ERROR() {
        return new TResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "SC_INTERNAL_SERVER_ERROR");
    }

    //public static TResponse customerError(String message) {
    //    return new TResponse(1001, message);
    //}

    @Override
    public String toString() {
        return "TResponse{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

}
